package com.ruoyi.web.controller.word;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.ErrorCode;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.domain.word.CommonWord;
import com.ruoyi.common.domain.word.vo.CommonWordSentenceVO;
import com.ruoyi.common.domain.word.vo.CommonWordVo;
import com.ruoyi.word.service.ICommonWordSentenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;

@RestController
@RequestMapping("/word/sentence")
public class CommonWordSentenceController extends BaseController {


    @Autowired
    private ICommonWordSentenceService biz;

    @PostMapping("/saveOrUpdate")
    public R saveOrUpdate(@RequestBody CommonWord record){
        try {
            if(record == null || record.getId() == null) {
                return R.fail(ErrorCode.INVALID_PARAMETERS);
            }
            return R.data(biz.saveCommonWordSen(record, record.getSentenceList()));
        }catch (Exception e){
            e.printStackTrace();
        }
        return R.fail();
    }

    @GetMapping("/findExSentence/{wid}")
    public R findExSentence(@PathVariable Long wid, @RequestParam(defaultValue = "0") Integer offset, @RequestParam(defaultValue = "50") Integer size) {
        try {
            startPage();
            return R.data(biz.findExSentence(wid));
        }catch (Exception e){
            e.printStackTrace();
        }
        return R.fail();
    }

}
